package com.example.mychess;

import javafx.scene.control.Alert;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;

import java.util.Objects;

import static com.example.mychess.LogonController.*;

public class ZhuceController {
    public TextField account;
    public PasswordField password;
    public PasswordField thePassword;

    public void zhuce(){
        String a=account.getText();
        String b=password.getText();
        String c=thePassword.getText();
        if(a==null|| Objects.equals(a,"")||b==null|| Objects.equals(b,"")||c==null|| Objects.equals(c,"")){
            Alert alert=new Alert(Alert.AlertType.ERROR);
            alert.setTitle("提示");
            alert.setHeaderText("提示");
            if(a==null|| Objects.equals(a,"")||b==null|| Objects.equals(b,"")){
            alert.setContentText("账号或密码不能为空");
            }
            else if(!b.equals(c)){
                alert.setContentText("请确认密码");}
            alert.showAndWait();
        }else{
            Message msg=new Message();
            msg.setUser(new User(a,b));
            msg.setType(Message.Type.ZHUCE);
            SocketUtil.send(socket,msg);
            msg=(Message) SocketUtil.receive(socket);
            if(msg.getType()==Message.Type.ZHUCE){
                Alert alert=new Alert(Alert.AlertType.INFORMATION);
                alert.setTitle("提示");
                alert.setHeaderText("提示");
                alert.setContentText("注册成功");
                alert.showAndWait();
                stage.show();
                zst.close();
            }
            else {
                Alert alert=new Alert(Alert.AlertType.ERROR);
                alert.setTitle("提示");
                alert.setHeaderText("提示");
                alert.setContentText("账号已存在");
                alert.showAndWait();
            }
        }
    }
    }
